package com.java.tutorials.spring.AfterReturningAdvice;

import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.framework.ProxyFactory;

import java.lang.reflect.Method;

/**
 * Created by xuzhike on 2016/1/28.
 * http://www.java2s.com/Code/Java/Spring/implementsAfterReturningAdvice.htm
 *implements AfterReturningAdvice
 */
public class implementsAfterReturningAdvice {
    public static void main(String[] args) throws Exception {
        MessageWriter target = new MessageWriter();

        // create the proxy
        ProxyFactory pf = new ProxyFactory();

        pf.addAdvice(new SimpleAfterReturningAdvice());
        pf.setTarget(target);

        MessageWriter proxy = (MessageWriter) pf.getProxy();

        // write the messages
        proxy.writeMessage();
    }
}

class MessageWriter {
    public void writeMessage() {
        System.out.println("A");
    }
}
class SimpleAfterReturningAdvice implements AfterReturningAdvice {
    public void afterReturning(Object returnValue, Method method, Object[] args,
                               Object target) throws Throwable {
        System.out.println("After method: " + method.getName());
    }
}
